package com.gensdai.leliang.adapter;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class KimiraAdapter<T> extends BaseAdapter {

	private List<T> mlist = new ArrayList<T>();

	public void add(List<T> mlist) {
		this.mlist = mlist;
		notifyDataSetChanged();
	}

	public void remove() {

	}

	public void clear() {
		if (mlist != null)
			mlist.clear();
		notifyDataSetChanged();
	}

	public List<T> getList() {
		return mlist;
	}

	public void append(List<T> mlist) {
		this.mlist.addAll(mlist);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return mlist.size();
	}

	@Override
	public Object getItem(int position) {
		return mlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	/**
	 * 适配器初始化后添加数据的必要方法
	 * @param list
	 */
	public void initAdd(List<T> list){
		this.mlist = new ArrayList<T>();
		this.mlist.addAll(list);
		notifyDataSetChanged();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return extralView(position, convertView, parent);
	}

	public abstract View extralView(int position, View convertView,
			ViewGroup parent);
}
